﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace SCRUM.Core.BusinessObjects
{
    /// <summary>
    /// Object represents project in this IS.
    /// Holds following information
    ///  * ID - object's unique identifier (among objects of same type)
    ///  * Name - name of object
    ///  * Estimation - estimation of total work on object
    ///  * Progress - progress of total work on object (in%)
    ///  * LastChange - date of last changes made to object
    ///  * Description - description of object
    /// </summary>
    [Serializable()]
    public class Project : DescriptedBusinessObject
    {
        /// <summary>
        /// Gets or sets the superior item's ID.
        /// </summary>
        /// <value>The superior item ID.</value>
        public override int SuperiorItemID
        {
            get { return -1; }
            set { }
        }

        /// <summary>
        /// Gets or sets the Customer.
        /// </summary>
        /// <value>The Customer.</value>
        public string Customer { get; set; }

        /// <summary>
        /// Gets or sets the StartDate.
        /// </summary>
        /// <value>The StartDate.</value>
        public DateTime StartDate { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="Project"/> class.
        /// </summary>
        /// <param name="id">Id of the project</param>
        /// <param name="state">State of the project</param>
        /// <param name="name">Logical name of project</param>
        /// <param name="startDate">Start date of project</param>
        /// <param name="customer">Customer of the project</param>
        public Project(int id, int stateID, string name, string description, double estimation, double progress, DateTime startDate, string customer, DateTime change)
            :base(id,name,description,estimation,progress,change, stateID)
        {
            this.StartDate = startDate;
            this.Customer = customer;
            this.stateType = State.StateTypes.Project;
        }

        /// <summary>
        /// Gets or sets the releases.
        /// </summary>
        /// <value>The releases.</value>
        public IList<Release> Releases
        {
            get
            {
                // Lazy loading
                if (this.releases == null)
                {
                    this.releases = DAO.DAORelease.GetAllReleasesForProject(this.ID);
                }
                return this.releases;
            }
            set
            {
                this.releases = value;
            }
        }

        /// <summary>
        /// Releases of the current project.
        /// </summary>
        private IList<Release> releases;
                
        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return this.Name;
        }
    }
}
